
#import "WXSDayDetailViewController.h"
#import "WXSDayDetailHeaderView.h"
#import "UUChart.h"
#import "WXSSleepInfoModel.h"

static NSString * const identifier = @"cell";

@interface WXSDayDetailViewController ()<UITableViewDelegate, UITableViewDataSource, UUChartDataSourceDelegate>
{
    UUChart *chartView;
}
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, copy) NSArray * dataArray;//数据源
@property (nonatomic, strong) WXSDayDetailHeaderView * headerView;//头部视图
@property (nonatomic, strong) WXSSleepInfoModel * sleepInfoModel;

- (void)_initializeAppearance;//初始化

@end

@implementation WXSDayDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self _initializeAppearance];
}

#pragma mark - private method

- (void)_initializeAppearance
{
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView;
    chartView = [[UUChart alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 145) dataSource:self style:UUChartStyleBar];
    chartView.backgroundColor = [UIColor clearColor];
    [chartView showInView:self.headerView.showChartView];
}

- (NSArray *)getXTitles:(int)num
{
    NSMutableArray *xTitles = [NSMutableArray array];
    for (int i=0; i<num; i++) {
        NSString * str = [NSString stringWithFormat:@"%d",i];
        [xTitles addObject:str];
    }
    return xTitles;
}

#pragma mark - UUChartDataSourceDelegate

- (NSArray *)chartConfigAxisXLabel:(UUChart *)chart
{
    return [self getXTitles:7];
}

- (NSArray *)chartConfigAxisYValue:(UUChart *)chart
{
    
#warning 假数据
    WXSDeepSleepStatusModel *deep = [[WXSDeepSleepStatusModel alloc]init];
    deep.statusDuration = 30;
    [self.sleepInfoModel.sleepStatusSequence addObject:deep];
    
    WXSShallowSleepStatusModel *shallow = [[WXSShallowSleepStatusModel alloc]init];
    shallow.statusDuration = 20;
    [self.sleepInfoModel.sleepStatusSequence addObject:shallow];
    
    WXSAwakeSleepStatusModel *awake = [[WXSAwakeSleepStatusModel alloc]init];
    awake.statusDuration = 5;
    [self.sleepInfoModel.sleepStatusSequence addObject:awake];
    
    WXSShallowSleepStatusModel *shallow1 = [[WXSShallowSleepStatusModel alloc]init];
    shallow1.statusDuration = 15;
    [self.sleepInfoModel.sleepStatusSequence addObject:shallow1];
    
    NSArray * modelArray = _sleepInfoModel.sleepStatusSequence;
    return modelArray;
}

- (NSArray *)chartConfigColors:(UUChart *)chart
{
    return @[[UUColor green],[UUColor red],[UUColor brown]];
}
//显示数值范围
- (CGRange)chartRange:(UUChart *)chart
{
    return CGRangeMake(100, 0);
}

#pragma mark - UITableViewDelegate

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - action


#pragma mark - lazy load

- (UITableView *)tableView
{
    if (_tableView == nil)
    {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0 , kScreenWidth, kScreenHeight - 64 - 30 - 49) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];
        _tableView.backgroundColor = [UIColor clearColor];
    }
    return _tableView;
}

- (WXSDayDetailHeaderView *)headerView
{
    if (_headerView == nil)
    {
        _headerView = [WXSDayDetailHeaderView loadHeaderView];
        _headerView.frame = CGRectMake(0, 0, kScreenWidth, 350 * kScreenHeightScale);
    }
    return _headerView;
}

- (WXSSleepInfoModel *)sleepInfoModel
{
    if (_sleepInfoModel == nil)
    {
        _sleepInfoModel = [[WXSSleepInfoModel alloc]init];
        _sleepInfoModel.totalSleepingTime = 300;
    }
    return _sleepInfoModel;
}


@end
